package lesson06.guess;

/**
 * 裁判类
 */
public class Judge {
    private Player player = new Player("小强",100);
    private Computer computer = new Computer("深蓝",100);

    /**
     * 将出拳的值进行转换
     */
    public String guessValueConvert(int guessValue){
        if(guessValue == 0){
            return "剪刀";
        }else if(guessValue == 1){
            return "石头";
        }else if(guessValue == 2){
            return "布";
        }else{
            return "未知";
        }
    }
    /**
     * 判断玩家和电脑出拳的输赢情况
     */
    public void check(){
        System.out.println("游戏开始");
        for(int i = 0;i < 10;i++){
            System.out.println("第"+(i+1)+"轮");
            int playerGuess = player.input();
            int computerGuess = computer.guess();
            System.out.println("电脑出拳：" + guessValueConvert(computerGuess));
            System.out.println("玩家出拳：" + guessValueConvert(playerGuess));
            if(playerGuess > computerGuess){
                if(playerGuess - computerGuess == 2){
                    computer.setScore(computer.getScore() + 10);
                    System.out.println("电脑赢，分数为：" + computer.getScore());
                }else{
                    player.setScore(player.getScore() + 10);
                    System.out.println("玩家赢，分数为：" + player.getScore());
                }
            }else if(playerGuess < computerGuess){
                if(computerGuess - playerGuess == 2){
                    player.setScore(player.getScore() + 10);
                    System.out.println("玩家赢，分数为：" + player.getScore());
                }else{
                    computer.setScore(computer.getScore() + 10);
                    System.out.println("电脑赢，分数为：" + computer.getScore());
                }
            }else{
                System.out.println("平局");
            }
        }
        System.out.println("玩家的分数：" + player.getScore()+"\n电脑的分数：" + computer.getScore());
        if(player.getScore() > computer.getScore()){
            System.out.println("玩家胜利");
        }else if(player.getScore() < computer.getScore()){
            System.out.println("电脑胜利");
        }else{
            System.out.println("打平");
        }

    }
}

